package com.cz.basetool.ui_work.util.et_bind;


import android.util.Pair;

import com.cz.basetool.R;
import com.cz.basetool.ui_work.util.txt.CZ_TextUtil;
import com.cz.basetool.ui_work.util.txt.RegularUtil;
import com.cz.basetool.ui_work.util.et_bind.base.BaseEditTextValidator;

/**
 * Created by 陈章 on 2017/4/12 0012.
 * func:
 * 手机号校验器
 */
public class MobilePhoneValidator extends BaseEditTextValidator {
    public MobilePhoneValidator() {
    }

    public MobilePhoneValidator(BaseEditTextValidator.OnValidatorResultObserver validatorResultObserver) {
        super(validatorResultObserver);
    }

    @Override
    public Pair validate(String phone) {
        //手机号为空
        if(CZ_TextUtil.is_null_or_empty(phone)){
            return getEmptyTipPair();
        }

        boolean check = RegularUtil.check(phone, "/^0[1-9][0-9]{1,3}[-][1-9][0-9]{5,7}|1[3|4|5|7|8|9][0-9]{9}$/");
        if(check == true) return  getRightPair();


        //手机号不合法
        if(!RegularUtil.isMobilePhoneNumber(phone)){
            return getErrorPair(mContext.getString(R.string.warn_input_mobilephone_illegal));
        }
        return getRightPair();
    }
}
